#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define INF 0x3f3f3f3f
using namespace std;
const int N = 1e5 + 10;
int n, q, c[N], u, v, s[N], t[N], vis[N];
vector<int> G[N];
map<pii, int> mp;

int bfs(int si, int ti)
{
	queue<pii> q;
	vis[si] = 1;
	q.push({si, 1<<c[si]});
	
	while(!q.empty())
	{
		int i = q.front().first, cnt = q.front().second;
		q.pop();
		
		
		if(i == ti)
		{
			int res = 0;
			for(int i = 0; i < 32; i++)
			{
				if(cnt & (1 << i)) res++;
			}
			return res;
		}
		
		for(int pos : G[i])
		{
			if(vis[pos]) continue;
			vis[pos] = 1;
			q.push({pos, cnt | (1 << c[pos])});
		}
	}
	
}

signed main()
{
	IOS;
	cin >> n >> q;
	for(int i = 1; i <= n; i++) cin >> c[i];
	for(int i = 1; i < n; i++)
	{
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	for(int i = 1; i <= q; i++)
	{
		cin >> s[i] >> t[i];
	}
	
	for(int i = 1; i <= q; i++)
	{
		memset(vis, 0, sizeof(vis));
		int S = s[i], T = t[i];
		if(S > T) swap(S, T);
		if(!mp.count({S,T})) mp[{S, T}] = bfs(S, T);
		cout << mp[{S, T}] << endl;
	}
	
	return 0;
 }

